// import type { User } from '@/types/user'
import { defineStore } from 'pinia'
import { ref } from 'vue'
/**
 * @Author: 段晓龙
 * @Date: 2024-08-20 19:20:16
 * @Description: 导航页签信息存储
 * @LastEditors: 段晓龙
 */
export const useNavTabStore = defineStore(
  'cnac-navtab',
  () => {
    // 多维报表 需要缓存的路由信息数组
    const multiInfoArry = ref<any>([])
    const setMultiInfo = (info: string, path: string) => {
      const obj = { info, path }
      // console.log('info', obj)
      if (multiInfoArry.value.findIndex((item: any) => item.path === path) === -1) {
        multiInfoArry.value.push(obj)
      } else {
        return false
      }
    }
    // 需要缓存的ifreame路由信息数组
    const iframeCacheArry = ref<any>([])
    const setIframeCache = (info: string, path: string) => {
      const obj = { info, path }
      if (iframeCacheArry.value.findIndex((item: any) => item.path === path) === -1) {
        iframeCacheArry.value.push(obj)
      } else {
        return false
      }
    }
    // 搜索页参数
    const searchParams = ref<any>()
    const setSearchParams = (params: any) => (searchParams.value = params)
    // 导航高亮
    const navActive = ref<string>('/home')
    const setNavActive = (path: string) => (navActive.value = path)
    // 导航页签
    const navTabList = ref<any>([])
    const setNavTab = (info: any) => {
      navTabList.value.push(info)
      navTabList.value = [...new Set(navTabList.value)]
    }
    const closeNavTab = (info: any) => {
      multiInfoArry.value = multiInfoArry.value.filter((item: any) => item.path !== info)
      iframeCacheArry.value = iframeCacheArry.value.filter((item: any) => item.path !== info)
      navTabList.value = navTabList.value.filter((item: any) => item.path !== info)
    }
    const clearNavTab = () => {
      navActive.value = '/home'
      navTabList.value = []
      searchParams.value = ''
      multiInfoArry.value = []
      iframeCacheArry.value = []
    }
    return {
      navActive,
      setNavActive,
      navTabList,
      setNavTab,
      closeNavTab,
      clearNavTab,
      searchParams,
      setSearchParams,
      iframeCacheArry,
      setIframeCache,
      multiInfoArry,
      setMultiInfo
    }
  },
  {
    persist: true // 开启持久化
  }
)
